package cc.fs.kotlin.data.service;

import android.content.Context;

import com.orhanobut.hawk.Hawk;
import com.orhanobut.hawk.HawkBuilder;
import com.orhanobut.hawk.LogLevel;

/**
 * Created by fostion on 2/19/16.
 * 本地持久化
 */
public class Local {

    /** 建议在application中初始化 */
    public static void init(Context context) {
        Hawk.init(context)
                .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
                .setStorage(HawkBuilder.newSqliteStorage(context))
                .setLogLevel(LogLevel.FULL)
                .build();
    }

    public static void set(String key, Object obj) {
        if (obj != null) {
            Hawk.put(key, obj);
        } else {
            Hawk.remove(key);
        }
    }

    public static <T> T get(String key) {
        return Hawk.get(key);
    }

}
